/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package umlapp.elements;

import java.awt.Color;
import java.awt.Graphics;
import umlapp.diagrams.Elements;

/**
 *
 * Trieda reprezentujúca elementy typu object.
 *
 * @author Peter Chovanec
 * @author Mario Jaros
 */
public class ObjectElement extends AElement implements Elements {

    /**
     * Konštruktor triedy s dvoma parametrami
     *
     * @param name meno elementu
     * @param dimension dimension elementu
     */
    public ObjectElement(String name, Dimension dimension) {
        super(name, dimension);
    }

    /**
     * Metoda na vykreslovanie elementu
     *
     * @param g
     */
    @Override
    public void drawElement(Graphics g) {
        dimension.width = name.length() * 7 + 30;
        dimension.height = 45;
        drawElementaryElement(g);
        drawName(g);
    }

    /**
     * Vykresluje zakladny obdlznik so vsetkymi ciarami.
     */
    public void drawElementaryElement(Graphics g) {
        g.setColor(Color.CYAN);
        g.fillRect(dimension.x, dimension.y, dimension.width, dimension.height);
        g.setColor(Color.BLACK);
        g.drawRect(dimension.x - 1, dimension.y - 1, dimension.width + 1, dimension.height + 1);
        g.drawLine(
                dimension.x,
                dimension.y + 15,
                dimension.x + dimension.width,
                dimension.y + 15);

    }

    /**
     * Napise meno triedy priblizne do stredu vertikalne.
     *
     */
    public void drawName(Graphics g) {
        int x = (dimension.x + (dimension.width / 2)) - (7 * (name.length() / 2));
        int y = dimension.y + 12;
        g.setColor(Color.BLACK);
        g.drawString(name, x, y);
    }
}
